<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      background-color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <h3>这是路由基础</h3>
    <router-link to="/home" tag="button">
      到首页
    </router-link>
    <router-link to="/news" tag="button">
      新闻页
    </router-link>
    <router-link to="/join" replace tag="button">
      加入我们
    </router-link>
    <!-- router-view 路由组件的出口 写在哪里 路由组件就在哪里渲染  -->
    <router-view/>
  </div>

  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    // 准备路由组件的options
    const Home = {
      template: `
        <div>
          <h2>首页</h2>  
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h2>新闻页</h2>  
        </div>
      `
    }
    const Join = {
      template: `
        <div>
          <h2>加入我们</h2>  
        </div>
      `
    }
    const routes = [
      {
        path: '/home',
        component: Home
      },
      {
        path: '/news',
        component: News
      },
      {
        path: '/join',
        component: Join
      }
    ] 
    // 创建路由对象
    const router = new VueRouter({
      // 路由规则 绝对了 有哪些路由 路由地址是什么，对应组件是什么
      routes
    })
    const vm = new Vue({
      el: '#app',
      router
    })
  </script>
</body>
</html>